package com.momalib.ning2_nocode.utils;

import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class NncConfUtil {

    public String convertPath(String rootPath, String path) {
        if (path != null && path.startsWith("file://")) {
            String tmpPath = path.substring(7);
            return rootPath + "/" + tmpPath;
        } else {
            return "";
        }
    }

    public boolean isIgnore(List<String> ignores, String rootPath, String filePath) {
        if (ignores == null || ignores.size() == 0) {
            return false;
        }
        String relativePath = rootPath == null || rootPath.length() == 0 ? filePath : filePath.replace(rootPath, "");
        for (String ignoreName: ignores) {
            if (relativePath.startsWith(ignoreName) || relativePath.replace("\\", "/").startsWith(ignoreName)) {
                return true;
            }
        }
        return false;
    }

}
